package net.wenku8.reader.view.common

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.lifecycle.viewmodel.compose.viewModel
import net.wenku8.reader.R
import net.wenku8.reader.enums.ColorType
import net.wenku8.reader.service.FileService


@Composable
fun ReadBgImage(){
    val readSettingModel = viewModel<ReadSettingModel>()
    val painter = when(readSettingModel.bgValue){
            ColorType.TYPE10.type -> painterResource(id = R.mipmap.reader_bg_yellow)
            ColorType.TYPE99.type -> FileService.imageAsPainter("/setting/readBgImage")
        else -> null
    }
    if (painter != null){
        Image(
            painter = painter,
            contentDescription = null,
            contentScale = ContentScale.FillBounds,
            modifier = Modifier.fillMaxSize()
        )
    }
}